package GUI;

import java.awt.Rectangle;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import java.awt.SystemColor;

public class ServerLoginGUI extends JFrame
{
	private JLabel portLabel = null;
	private JLabel  my_SQLpasswordLabel = null;
	private JLabel  my_SQLusernamedLabel = null;
	private JTextField portLabelField = null;
	private JTextField my_SQLusernameField = null;
	private JPasswordField my_SQLpasswordField = null;
	private JButton startButton = null;
	private JPanel jContentPane = null;
	
	/**
	 * This is the default constructor
	 */
	public ServerLoginGUI() 
	{
		super();
		initialize();		
	}
	
	/**
	 * This method initializes ServerInitialize
	 */
	private void initialize()
	{
		this.setSize(400, 300);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setContentPane(getJContentPane());
		this.setTitle("Welcome to CCRM Server");		
	}
	/**
	 * This method initializes LoginForm
	 */
	private JPanel getJContentPane() 
	{
		if (jContentPane == null) 
		{
			jContentPane = new JPanel();
			jContentPane.setBackground(SystemColor.desktop);
			jContentPane.setLayout(null);
			portLabel  = new JLabel();
			portLabel .setBounds(new Rectangle(15, 30, 113, 22));
			portLabel .setText("Port");
			
			my_SQLusernamedLabel = new JLabel();
			my_SQLusernamedLabel.setBounds(new Rectangle(15, 70, 113, 22));
			my_SQLusernamedLabel.setText("MySQL user name");
			
			my_SQLpasswordLabel = new JLabel();
			my_SQLpasswordLabel.setBounds(new Rectangle(15, 110, 113, 22));
			my_SQLpasswordLabel.setText("MySQL password");
			
			jContentPane.add(portLabel, null);
			jContentPane.add(my_SQLpasswordLabel, null);
			jContentPane.add(my_SQLusernamedLabel, null);
			jContentPane.add(getPortLabelField(), null);
			jContentPane.add(getMy_SQLusernameField(), null);
			jContentPane.add(getMy_SQLpasswordField(), null);
			jContentPane.add(getStartButton(),null);
		}
		return jContentPane;		
	}
	
	/**
	 * This method initializes portLabelField	
	 */
	private JTextField getPortLabelField()
	{
		if (portLabelField == null) 
		{
			portLabelField = new JTextField();
			portLabelField.setBounds(new Rectangle(138, 30, 130, 22));
		}
		return portLabelField;
	}
	
	
	/**
	 * This method initializes my_SQLusernameField	
	 */
	private JTextField getMy_SQLusernameField()
	{
		if (my_SQLusernameField == null) 
		{
			my_SQLusernameField = new JTextField();
			my_SQLusernameField.setBounds(new Rectangle(138, 70, 130, 22));
			my_SQLusernameField.setText("root");
		}
		return my_SQLusernameField;
	}
	
	/**
	 * This method initializes my_SQLpasswordField	
	 */
	private JPasswordField getMy_SQLpasswordField()
	{
		if (my_SQLpasswordField == null) 
		{
			my_SQLpasswordField = new JPasswordField();
			my_SQLpasswordField.setBounds(new Rectangle(138, 110, 130, 22));
			my_SQLpasswordField.setText("Braude");
		}
		return my_SQLpasswordField;
	}
	
	/**
	 * This method initializes startButton	
	 */
	public JButton getStartButton() 
	{
		
		if (startButton == null) 
		{
			startButton = new JButton();
			startButton.setBounds(new Rectangle(148, 171, 110, 29));
			startButton.setText("START");
		}	
		return startButton;
	}	
	 
	/**
	 *  This method return the entered port	
	 */
	public int getPort()
	{
		int port=0;
		String msg;
		try
		{
			if (portLabelField != null)
			{
				msg = portLabelField.getText();
				if (msg.equals(""))
					return 0;
				port = Integer.parseInt(msg);
			}	
			return port;
		}catch (Exception e)
		{
			return -1;
		}		
	}
	
	/**
	 *  This method return the entered port	MySQL userName
	 */
	public String getMySQLuserName()
	{
		if (my_SQLusernameField != null)
			return my_SQLusernameField.getText();
		return null;		
	}
	
	/**
	 *  This method return the entered MySQL password	
	 */
	public char[] getMySQLpassword()
	{
		if (my_SQLpasswordField != null)
			return my_SQLpasswordField.getPassword();
		return null; 		
	}
	
		
}
